﻿@model NetSurveillance.WebApp.Models.AdslModel
@{
    ViewBag.Title = Resources.MenuResource.SystemSetting_ADSLSetting;
    Layout = "~/Views/Shared/_SystemConfigLayout.cshtml";
    ViewBag.CurrentMiddleMenu = 3;
    ViewBag.CurrentMainMenu = 5;
}

<h3 id="contentHeader">
    @ViewBag.Title
</h3>
@using (Html.BeginForm())
{
    <div id="monitorContent" class="config_content0">
        <table id="tbADSL">
            <tr>
                <td colspan="5">DATA PVC</td>
            </tr>
            <tr>
                <td>VPI</td>
                <td>
                    @Html.TextBoxFor(m => m.DataPVCVPI)
                    @Html.ValidationMessageFor(m => m.DataPVCVPI)
                </td>
                <td>VCI</td>
                <td>
                    @Html.TextBoxFor(m => m.DataPVCVCI)
                    @Html.ValidationMessageFor(m => m.DataPVCVCI)
                </td>
                <td>
                    <dl class="filemanage_right_dl">
                        <dd id="btnScan"><a href="javascript:;">@Resources.Resource.Button_Read</a></dd>      
                    </dl>
                </td>
            </tr>
            <tr>
                <td colspan="5">IPTV PVC</td>
            </tr>
            <tr>
                <td>VPI</td>
                <td>
                    @Html.TextBoxFor(m => m.IptvPVCVPI)
                    @Html.ValidationMessageFor(m => m.IptvPVCVPI)
                </td>
                <td>VCI</td>
                <td colspan="2">
                    @Html.TextBoxFor(m => m.IptvPVCVCI)
                    @Html.ValidationMessageFor(m => m.IptvPVCVCI)
                </td>
            </tr>
        </table>
        <div>
            <p>说明:</p>
            <p>
                由于使用ADSL监控时，需要设置相应数据和IPTV的PVC参数，每个地区的参数都有可能不一样，因此需要拨打当地电信客服电话进行
                询问，在获得正确参数后，请在此处进行设置。
            </p>
            <p>
                注意：为了保证监控正常进行，请在设置了相关参数后，先找一个实验目标进行测试，然后再进行正式监控。
            </p>
        </div>
        <div class="buttonsContain">
            @Html.Hidden("Id", null)
            <ul class="config_bottom_btndivs">
                <li>
                    <input type="button" id="btnSaveQuery" value="@Resources.Resource.Button_Apply"/>
                </li>
                <li>
                    <input type="reset" id="btnResetChanges" value="@Resources.Resource.Button_ResetChanges"/>
                </li>    
            </ul>
        </div>
    </div>
}
@section css{
    <style type="text/css">
        #contentHeader
        {
            text-align: center;
            margin: 5px 0 10px 0;
            font-size: 1.5em;
        }
        #tbADSL {
            width: 60%;
            margin: 0 auto;
        }
        #tbADSL tr {
            height: 30px;
            line-height: 30px;
        }
    </style>
}
@section javascript
{
    <script type="text/javascript">
        $(function() {
            $('#btnScan').click(function() {
                var $hidId = $('#Id'), id = $hidId.val();
                if (id > 0) {
                    $.showLoading('正在读取Adsl信息');
                    readAdsl(id);
                    return;
                }
                alert('无法发送读取ADSL值命令，数据库中无对应MonitorSetting数据');
            });
            $('#btnSaveQuery').click(function() {
                if ($('form').valid()) {
                    $.showLoading('正在设置Adsl信息');
                    setAdsl();
                }
                return false;
            });
        });

        function readAdsl(id) {
            $.ajax({
                url: '@Url.Action("ReadAdsl")',
                cache: false,
                type: 'post',
                dataType: 'json',
                data: { msId: id },
                success: function (result) {
                    if (!result || !result.success || result.expandos)
                        $.hideLoading();
                    if (!result) {
                        alert('读取失败');
                        return;
                    }
                    if (!result.success)
                        alert(result.message);
                    if (result.expandos) {
                        $('#DataPVCVPI').val(result.expandos.dataPVCVPI);
                        $('#DataPVCVCI').val(result.expandos.dataPVCVCI);
                        $('#IptvPVCVPI').val(result.expandos.iptvPVCVPI);
                        $('#IptvPVCVCI').val(result.expandos.iptvPVCVCI);
                    }
                    if (result.success && !result.expandos)
                        setTimeout(function() { readAdsl(id); }, 3000);
                }
            });
        }

        function setAdsl() {
            var adslObj = $('form').serializeObject();
            $.ajax({
                url: '@Url.Action("ADSLSetting")',
                cache: false,
                type: 'post',
                dataType: 'json',
                data: adslObj,
                success: function(result) {
                    if (!result || !result.success || result.expandos)
                        $.hideLoading();
                    if (!result) {
                        alert('设置失败');
                        return;
                    }
                    if (!result.success)
                        alert(result.message);
                    if (result.expandos) {
                        $('#Id').val(result.expandos.id);
                    }
                    if (result.success && !result.expandos)
                        setTimeout(setAdsl, 3000);
                }
            });
        }
    </script>
}
